package com.efivestar.idm.api.rest;

import com.efivestar.idm.api.common.Cons;
import com.efivestar.idm.api.common.ResultDto;
import com.efivestar.idm.api.config.SpringContextHelper;
import com.efivestar.idm.api.domain.*;
import com.efivestar.idm.api.exception.AppException;
import com.efivestar.idm.api.repository.CameraMapper;
import com.efivestar.idm.api.repository.TianyiUserMapper;
import com.efivestar.idm.api.repository.WeixinJoinDeviceMapper;
import com.efivestar.idm.api.repository.WeixinUserMapper;
import com.efivestar.idm.api.rest.vm.DoorRemoteControlVM;
import com.efivestar.idm.api.rest.vm.PasswordVM;
import com.efivestar.idm.api.service.DeviceService;
import com.efivestar.idm.api.service.TianyiUserService;
import com.efivestar.idm.api.service.WeixinService;
import com.efivestar.idm.api.service.dto.DeviceBindDto;
import com.efivestar.idm.api.service.dto.DeviceWithNameDto;
import com.efivestar.idm.api.service.dto.EventDto;
import com.efivestar.idm.api.service.dto.UserDto;
import com.efivestar.idm.api.service.lock.protocol.handler.WarningLockProtocolHandler;
import com.efivestar.idm.api.util.ByteUtils;
import com.efivestar.idm.api.util.tianyi.GetPlayUrlHXReq;
import com.efivestar.idm.api.util.tianyi.GetPlayUrlHXRes;
import com.efivestar.idm.api.util.tianyi.MobileServicesPortType;
import com.efivestar.idm.api.util.weixin.ContextHolder;
import com.efivestar.idm.api.util.weixin.WeixinApi;
import com.efivestar.idm.api.util.weixin.bean.JsTicketSignuature;
import com.efivestar.idm.api.util.weixin.bean.OAuth2AccessToken;
import com.github.pagehelper.PageInfo;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
public class WeixinLockController {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private WeixinApi weixinApi;

    @Autowired
    private Environment env;

    @Autowired
    private WeixinUserMapper weixinUserMapper;

    @Autowired
    private WeixinService weixinService;

    @Autowired
    private CameraMapper cameraMapper;

    @Autowired
    private DeviceService deviceService;

    @Autowired
    private TianyiUserMapper tianyiUserMapper;

    @Autowired
    private MobileServicesPortType mobileServicesPortType;

    @Autowired
    private TianyiUserService tianyiUserService;

    @Autowired
    private WeixinJoinDeviceMapper weixinJoinDeviceMapper;


    /**
     * 获取当前微信用户的openId
     *
     * @param map
     * @param redirectUrl
     * @param code
     * @param state
     * @param response
     * @throws IOException
     */
    @RequestMapping("/getOpenId")
    public void getOpenId(Map<String, Object> map, String redirectUrl, String code, String state, HttpServletResponse response) throws IOException {
        OAuth2AccessToken oAuth2AccessToken = weixinApi.getOAuth2AccessToken(code);
        String openid = oAuth2AccessToken.getOpenid();
        Cookie oidCookie = new Cookie("oid", openid);
        oidCookie.setMaxAge(265 * 24 * 60 * 60);// (s)
        oidCookie.setPath("/");
        String signatureKey = env.getProperty("openId.signature-key");
        Cookie signatureCookie = new Cookie("sign", DigestUtils.md5Hex(openid + signatureKey));
        signatureCookie.setMaxAge(265 * 24 * 60 * 60);// (s)
        signatureCookie.setPath("/");
        response.addCookie(oidCookie);
        response.addCookie(signatureCookie);
        response.sendRedirect(redirectUrl);
    }

    @RequestMapping("/index")
    public String helloHtml(Model map) {
        map.addAttribute("hello", "from TemplateController.helloHtml");
        return "/helloHtml";
    }


    /**
     * 设备详情界面.
     *
     * @param map
     * @return
     */
    @RequestMapping("/deviceInfo")
    public String deviceInfo(Map<String, Object> map) {
        map.put("hello", "from TemplateController.helloHtml");
        return "device-info";
    }

    @RequestMapping("/distIndex")
    public String distIndex(Map<String, Object> map) {
        return "index";
    }

    /**
     * 设备事件界面.
     *
     * @param map
     * @return
     */
    @RequestMapping("/deviceEvent")
    public String deviceEvent(Model map, @RequestParam(name = "eventId", required = false) String eventId) {
        map.addAttribute("eventId", eventId);
        List<Lock2UserDomain> lock2UserDomains = weixinService.queryLockUsers();
        map.addAttribute("users", lock2UserDomains);
        return "device-event";
    }

    @RequestMapping("/getUsers")
    public @ResponseBody
    List<Lock2UserDomain> getUsers() {
        return weixinService.queryLockUsers();
    }

    /**
     * 设备维护 界面.
     *
     * @param map
     * @return
     */
    @RequestMapping("/deviceManage")
    public String deviceManage(Map<String, Object> map) {
        map.put("hello", "from TemplateController.helloHtml");
        return "device-manage";
    }


    /**
     * 设备绑定 界面.
     *
     * @param map
     * @return
     */
    @GetMapping("/deviceBind")
    public String deviceBind(Map<String, Object> map) {
        return "device-bind";
    }


    /**
     * 天翼登录.
     */
    @PostMapping("/tianyiLogin")
    public @ResponseBody
    ResultDto tianyiLogin(@RequestBody Map<String, String> tianyiUser) {
        String account = tianyiUser.get("account");
        String password = tianyiUser.get("password");

        String openId = ContextHolder.getWeixinUser().getOpenId();
        WeixinJoinDeviceDomain dto = new WeixinJoinDeviceDomain();
        dto.setOpenId(openId);
        WeixinJoinDeviceDomain dbWeixinJoinDeviceDomain = weixinJoinDeviceMapper.selectByPrimaryKey(dto);

        ResultDto loginResult = tianyiUserService.login(account, password, dbWeixinJoinDeviceDomain.getCameraId());
        // 登录成功，此时天翼用户也已经被插入到表中
        if ("true".equals(loginResult.getSuccess())) {
            // 更新当前设备对应的用户名
            dbWeixinJoinDeviceDomain.setCameraAccount(account);
            weixinJoinDeviceMapper.updateByPrimaryKey(dbWeixinJoinDeviceDomain);
        } else {
            return loginResult;
        }
        return ResultDto.builder().success("true").build();
    }

    /**
     * 用户管理 界面.
     *
     * @param map
     * @return
     */
    @GetMapping("/userManage")
    public String userManage(Map<String, Object> map) {
        return "user-manage";
    }

    /**
     * 摄像头 界面.
     *
     * @param map
     * @return
     */
    @RequestMapping("/cameraPage")
    public String cameraPage(Map<String, Object> map) {
//        String openId = ContextHolder.getWeixinUser().getOpenId();
//        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
//        DeviceWithNameDto deviceWithNameDto = null;
//        String cameraUrl = "";
//        if (devices != null && !devices.isEmpty()) {
//            deviceWithNameDto = devices.get(0);
//            String cameraId = deviceWithNameDto.getCameraId();
//            if (StringUtils.isNotEmpty(cameraId)) {
//                CameraDomain cameraDomain = cameraMapper.selectByPrimaryKey(CameraDomain.builder().cameraId(cameraId).build());
//                if (cameraDomain != null) {
//                    cameraUrl = cameraDomain.getUrl();
//                }
//            }
//        }
//        map.put("cameraUrl", cameraUrl);
        return "camera-page";
    }

    /**
     * 获取摄像头的播放地址.
     *
     * @return
     */
    @GetMapping("/getCameraUrl")
    public @ResponseBody
    ResultDto getCameralUrl() {
        ResultDto.ResultDtoBuilder builder = ResultDto.builder();
        String openId = ContextHolder.getWeixinUser().getOpenId();
        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
        DeviceWithNameDto deviceWithNameDto;
        if (devices != null && !devices.isEmpty()) {
            deviceWithNameDto = devices.get(0);
            String cameraId = deviceWithNameDto.getCameraId();
            if (StringUtils.isNotEmpty(cameraId)) {
                int cameraType = weixinService.getCameraType(cameraId);
                if (0 == cameraType) {// 电信摄像头
                    return getTianyiCameralPlayUrl();
                } else if (1 == cameraType) {// 物联摄像头
                    CameraDomain cameraDomain = cameraMapper.selectByPrimaryKey(CameraDomain.builder().cameraId(cameraId).build());
                    if (cameraDomain != null) {
                        String cameraUrl = cameraDomain.getUrl();
                        builder.success("true").data(cameraUrl);
                        return builder.build();
                    }
                }
            }
        }

        ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
        exceptionObj.setCode("not_exist_device");
        builder.success("false").exceptionObj(exceptionObj);
        return builder.success("false").build();
    }


    /**
     * 获取天翼的播放摄像地址.
     *
     * @return
     */
    public ResultDto getTianyiCameralPlayUrl() {
        ResultDto.ResultDtoBuilder builder = ResultDto.builder();
        String openId = ContextHolder.getWeixinUser().getOpenId();
        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
        DeviceWithNameDto deviceWithNameDto;
        if (devices != null && !devices.isEmpty()) {
            deviceWithNameDto = devices.get(0);
            // 摄像头账户
            String cameraAccount = deviceWithNameDto.getCameraAccount();
            TianyiUserDomain tianyiUserDomain = tianyiUserMapper.selectByPrimaryKey(cameraAccount);
            if (tianyiUserDomain == null) {
                logger.error("tianyiUser not found !");

                ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
                // 智能锁平台尚未添加天翼账户
                exceptionObj.setCode("tianyi.account_not_exist");
                builder.success("false").exceptionObj(exceptionObj);
                return builder.build();
            }

            String session = tianyiUserDomain.getSession();
            GetPlayUrlHXRes tianyiPlayUrl = getTianyiPlayUrl(cameraAccount, session, deviceWithNameDto.getCameraId());
            // 获取天翼返回url的状态码.
            int result = tianyiPlayUrl.getResult();
            // session 过期,重新登录一次
            if (result == 2) {
                // 再次登录
                ResultDto loginResult = tianyiUserService.login(cameraAccount, tianyiUserDomain.getPassword(), deviceWithNameDto.getCameraId());
                if ("true".equals(loginResult.getSuccess())) {
                    // 重新再次获取一次播放地址.
                    tianyiPlayUrl = getTianyiPlayUrl(cameraAccount, session, deviceWithNameDto.getCameraId());
                    result = tianyiPlayUrl.getResult();
                } else {
                    return loginResult;
                }
            }
            // 调用成功
            if (result == 0) {
                builder.success("true").data(tianyiPlayUrl.getRelayPlayUrl());
            } else if (result == 1) {
                ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
                // 天翼用户不存在
                exceptionObj.setCode("tianyi.not_exist_account");
                builder.success("false").exceptionObj(exceptionObj);
            } else if (result == 2) {
                ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
                // session 异常
                exceptionObj.setCode("tianyi.invalid_session");
                builder.success("false").exceptionObj(exceptionObj);
            } else if (result == 3) {
                ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
                // 设备不存在
                exceptionObj.setCode("tianyi.not_exist_device");
                builder.success("false").exceptionObj(exceptionObj);
            } else if (result == 4) {
                ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
                // 设备不在线
                exceptionObj.setCode("tianyi.device_not_online");
                builder.success("false").exceptionObj(exceptionObj);
            } else if (result == 11) {
                ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
                // 摄像头未开启 或未绑定
                exceptionObj.setCode("tianyi.other_place_login");
                builder.success("false").exceptionObj(exceptionObj);
            }
        } else {
            ResultDto.ExceptionObj exceptionObj = new ResultDto.ExceptionObj();
            exceptionObj.setCode("not_exist_device");
            builder.success("false").exceptionObj(exceptionObj);
        }

        return builder.build();
    }

    public GetPlayUrlHXRes getTianyiPlayUrl(String cameraAccount, String session, String cameraId) {
        GetPlayUrlHXReq getPlayUrlHXReq = new GetPlayUrlHXReq();
        getPlayUrlHXReq.setAccount(cameraAccount);
        getPlayUrlHXReq.setLoginSession(session);
        // 设置摄像头id
        getPlayUrlHXReq.setDevID(cameraId);
        getPlayUrlHXReq.setChannelNo(0);
        // 标清视频
        getPlayUrlHXReq.setStreamType(2);
        GetPlayUrlHXRes playUrlHX = mobileServicesPortType.getPlayUrlHX(getPlayUrlHXReq);
        return playUrlHX;
    }


    /**
     * 前端获取签名.
     * @param urlVM
     * @return

     @RequestMapping("/getJsTicketSignuature") public @ResponseBody JsTicketSignuature getJsTicketSignuature(@RequestBody JsTicketUrlVM urlVM){
     return weixinApi.getJSTicketSignature(urlVM.getUrl());
     }
     */
    /**
     * 前端获取签名.
     *
     * @return
     */
    @RequestMapping("/getJsTicketSignuature")
    public @ResponseBody
    JsTicketSignuature getJsTicketSignuature(String url) {
        return weixinApi.getJSTicketSignature(url);
    }


    /**
     * 获取我的设备列表.
     *
     * @return
     */
    @GetMapping("/myDevice")
    public @ResponseBody
    ResultDto myDevice() {
        String openId = ContextHolder.getWeixinUser().getOpenId();
        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
        DeviceWithNameDto deviceWithNameDto = null;
        if (devices != null && !devices.isEmpty()) {
            deviceWithNameDto = devices.get(0);
        }
        return ResultDto.builder().data(deviceWithNameDto).build();
    }

//    /**
//     * 删除当前用户的某一个设备.
//     * 该方法不用
//     * @param deviceId
//     * @return
//     */
//    @DeleteMapping("/deleteMyDevice/{deviceId}")
//    public @ResponseBody
//    ResultDto deleteMyDevice(@PathVariable("deviceId") String deviceId){
//        String openId = ContextHolder.getWeixinUser().getOpenId();
//        weixinService.deleteUserDevice(openId, deviceId);
//        return ResultDto.builder().build();
//    }


    @PostMapping("/unBindLock")
    public @ResponseBody
    ResultDto unBindLock(@RequestBody WeixinJoinDeviceDomain weixinJoinDeviceDomain) {
        weixinService.unBindDevice(weixinJoinDeviceDomain, Cons.LOCK);
        return ResultDto.builder().build();
    }


    @PostMapping("/unBindCamera")
    public @ResponseBody
    ResultDto unBindCamera(@RequestBody WeixinJoinDeviceDomain weixinJoinDeviceDomain) {
        weixinService.unBindDevice(weixinJoinDeviceDomain, Cons.CAMERA);
        return ResultDto.builder().build();
    }


    @PostMapping("/bindDeviceToUser")
    public @ResponseBody
    ResultDto bindDeviceToUser(@RequestBody DeviceBindDto deviceBindDto) {
        weixinService.bindDeviceToUser(deviceBindDto);
        return ResultDto.builder().build();
    }

    @PostMapping("/unBindDeviceToUser")
    public @ResponseBody
    ResultDto unBindDeviceToUser() {
        weixinService.unBindDeviceToUser();
        // 解绑成功，则要清空cookie中的数据
        return ResultDto.builder().build();
    }


    @RequestMapping("/warning")
    public @ResponseBody
    ResultDto warning() {
        String openId = ContextHolder.getWeixinUser().getOpenId();
        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
        DeviceWithNameDto deviceWithNameDto = null;
        if (devices != null && !devices.isEmpty()) {
            deviceWithNameDto = devices.get(0);
            String deviceId = deviceWithNameDto.getDeviceId();
            byte[] bytes = ByteUtils.hexToBytes(generateWarningHex(deviceId));
            ByteBuf actualByteBuf = Unpooled.copiedBuffer(bytes);
            WarningLockProtocolHandler warningLockProtocolHandler = SpringContextHelper.getBean("WarningLockProtocolHandler");
            warningLockProtocolHandler.execute(actualByteBuf);
        }

        return ResultDto.builder().build();
    }


    @RequestMapping("/eventPage")
    public @ResponseBody
    ResultDto eventPage(@RequestBody EventDto eventDto, PageInfo page) {
        String openId = ContextHolder.getWeixinUser().getOpenId();
        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
        DeviceWithNameDto deviceWithNameDto = null;
        if (devices != null && !devices.isEmpty()) {
            deviceWithNameDto = devices.get(0);
        }
        PageInfo events = null;
        //绑定关系存在并且智能锁存在.
        if (deviceWithNameDto != null && StringUtils.isNotEmpty(deviceWithNameDto.getDeviceId())) {
            eventDto.setDeviceId(deviceWithNameDto.getDeviceId());
            events = weixinService.selectEventByPage(eventDto, page);
        } else {
            events = page;
            events.setTotal(0);
            events.setList(new ArrayList());
            events.setSize(0);
        }

        return ResultDto.builder().data(events).build();
    }


    private String generateWarningHex(String device) {
        String headHex = "ef01";
        String addressHex = "ffffffff";
        String definHex = "01";
        Short dataLength = (short) (5 + device.length());
        String dataLengthHex = ByteUtils.bytes2hex(shortToByte(dataLength));
        String dataHex = "c52003";
        String deviceId = device;
        String deviceHexIdHex = ByteUtils.bytes2hex(getDeviceIdBts(deviceId));
        String checksumHex = ByteUtils.bytes2hex(getCheckSum(definHex, dataLengthHex, dataHex + deviceHexIdHex));

        StringBuffer sb = new StringBuffer(headHex);
        String result = sb.append(addressHex).append(definHex).append(dataLengthHex).append(dataHex + deviceHexIdHex).append(checksumHex).append("1a").toString();
        return result;
    }

    public byte[] shortToByte(short number) {
        int temp = number;
        byte[] b = new byte[2];
        int length = b.length;
        for (int i = 0; i < length; i++) {
            b[length - i - 1] = new Integer(temp & 0xff).byteValue();//
//            将最低位保存在最低位
            temp = temp >> 8; // 向右移8位
        }
        return b;
    }


    private byte[] getDeviceIdBts(String deviceId) {
        byte[] bytes = new byte[deviceId.length()];
        for (int i = 0; i < deviceId.length(); i++) {
            bytes[i] = (byte) deviceId.charAt(i);
        }
        return bytes;
    }

    private static byte[] getCheckSum(String detification, String lengthPacket, String data) {
        byte[] detiBts = ByteUtils.hexToBytes(detification);
        ByteBuf detificationBBF = Unpooled.copiedBuffer(detiBts);
        byte[] lengBts = ByteUtils.hexToBytes(lengthPacket);
        ByteBuf lengthPcketnBBF = Unpooled.copiedBuffer(lengBts);
        byte[] dataBts = ByteUtils.hexToBytes(data);
        ByteBuf dataPacketnBBF = Unpooled.copiedBuffer(dataBts);
        int sum = 0;
        for (int i = 0; i < detiBts.length; i++) {
            sum += detificationBBF.readUnsignedByte();
        }
        for (int i = 0; i < lengBts.length; i++) {
            sum += lengthPcketnBBF.readUnsignedByte();
        }
        for (int i = 0; i < dataBts.length; i++) {
            sum += dataPacketnBBF.readUnsignedByte();
        }
        return ByteUtils.intToBytes(sum);
    }


    /**
     * 智能锁对应的用户列表.
     *
     * @return
     */
    @GetMapping("/lock2Users")
    public @ResponseBody
    ResultDto queryLock2Users() {
        List<Lock2UserDomain> lock2UserDomains = weixinService.queryLockUsers();
        return ResultDto.builder().data(lock2UserDomains).build();
    }


    /**
     * 更新智能锁对应的用户列表.
     *
     * @return
     */
    @PostMapping("/updateUserNameAndHijackStatus")
    public @ResponseBody
    ResultDto queryLock2Users(@RequestBody List<UserDto> userDtos) {
        weixinService.updateUserNameAndHijackStatus(userDtos);
        return ResultDto.builder().data(true).build();
    }

    @RequestMapping("/descriptionPage")
    public String descriptionPage() {
        return "soft-description";
    }


    /**
     * 远程开锁界面.
     *
     * @return
     */
    @GetMapping("/remoteOpenDoor")
    public String remoteOpenDoor(Model map, @RequestParam(name = "notification", required = false) String notification) {
        if (StringUtils.isNotEmpty(notification)) {
            map.addAttribute("notification", true);
        } else {
            map.addAttribute("notification", false);
        }
        return "remote-opendoor";
    }


    /**
     * 获取智能锁对应的远程开锁状态.
     *
     * @return
     */
    @GetMapping("/getMyLockRemoteControl")
    public @ResponseBody
    ResultDto getMyLockRemoteControl() {
        LockRemoteControlDomain myLockRemoteControl = weixinService.getMyLockRemoteControl();
        return ResultDto.builder().data(myLockRemoteControl).build();
    }

    /**
     * 远程开门或拒绝开门.
     *
     * @param doorRemoteControlVM
     * @return
     */
    @PostMapping("/remoteControlOpDoor")
    public @ResponseBody
    ResultDto remoteControlOpDoor(@RequestBody DoorRemoteControlVM doorRemoteControlVM) {
        weixinService.remoteControlOpDoor(doorRemoteControlVM);
        return ResultDto.builder().data(true).build();
    }

    /**
     * 获取最新的一次开门事件.
     *
     * @return
     */
    @GetMapping("/getLatestOpenDoorEvent")
    public @ResponseBody
    ResultDto getLatestOpenDoorEvent() {
        EventDomain latestOpenDoorEvent = weixinService.getLatestOpenDoorEvent();
        return ResultDto.builder().data(latestOpenDoorEvent).build();
    }

    /**
     * 修改远程开锁密码.
     *
     * @param passwordVM
     * @return
     */
    @PostMapping("/changePassword")
    public @ResponseBody
    ResultDto changePassword(@RequestBody PasswordVM passwordVM) {
        if (StringUtils.isEmpty(passwordVM.getOldPassword())) {
            throw new AppException("100", "原密码不允许为空");
        }
        weixinService.modifyRemoteOpenDoorPassword(passwordVM.getOldPassword(), passwordVM.getNewPassword());
        return ResultDto.builder().data(true).build();
    }

    /**
     * 重置远程开锁密码.
     *
     * @param passwordVM
     * @return
     */
    @PostMapping("/resetPassword")
    public @ResponseBody
    ResultDto resetPassword(@RequestBody PasswordVM passwordVM) {
        weixinService.reSetRemoteOpenDoorPassword(passwordVM.getNewPassword());
        return ResultDto.builder().data(true).build();
    }

    @PostMapping("/changeDefenseStatus")
    public @ResponseBody
    ResultDto changeDefenseStatus(@RequestBody DeviceDomain deviceDomain) {
        String openId = ContextHolder.getWeixinUser().getOpenId();
        List<DeviceWithNameDto> devices = weixinUserMapper.getDevicesByOpenId(openId);
        DeviceWithNameDto deviceWithNameDto = null;
        if (devices != null && !devices.isEmpty()) {
            deviceWithNameDto = devices.get(0);
            String deviceId = deviceWithNameDto.getDeviceId();
            deviceService.updateDefenseStatus(deviceId, deviceDomain.getDefenseStatus());
        }
        return ResultDto.builder().build();
    }

}
